package com.teemor.open.openauthspringbootstarter.config;

import com.teemor.open.openauth.validator.AuthValidator;
import com.teemor.open.openauth.validator.BaseRoleValidator;
import com.teemor.open.openauth.validator.RoleValidator;
import com.teemor.open.openauthspringbootstarter.gateway.filter.AuthGatewayFilterFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/6/3 14:16
 */
@Configuration
@ConditionalOnClass(org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory.class)
public class OpenAuthAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(AuthValidator.class)
    public AuthValidator authValidator() {
        return new AuthValidator();
    }

    @Bean
    @ConditionalOnMissingBean(RoleValidator.class)
    public RoleValidator<Boolean> roleValidator() {
        return new BaseRoleValidator();
    }

    @Bean
    public AuthGatewayFilterFactory authGatewayFilterFactory() {
        return new AuthGatewayFilterFactory();
    }
}
